package com.hiwan.system.util;


import com.hiwan.platform.utils.SpringContextHolder;
import com.hiwan.system.dao.org.OrgDao;
import com.hiwan.system.pojo.OrgInfo;

/***
 * @time 2016-01-15
 * @author 李仕波
 */
public class OrgCacheUtils {

	private static OrgDao orggDao = SpringContextHolder.getBean(OrgDao.class);
	public static final String ORG_CACHE = "orgCache";
	
	/**
	 * 根据ID获取机构信息
	 * @param id
	 * @return 取不到返回null
	 */
	public static OrgInfo get(String orgId){
		OrgInfo orgInfo = (OrgInfo)CacheUtils.get(ORG_CACHE, orgId);
		if (orgInfo ==  null){
			orgInfo = orggDao.selectOrgInfo(orgId);
			if (orgInfo == null){
				orgInfo = new OrgInfo();
				return orgInfo;
			}
			CacheUtils.put(ORG_CACHE,orgId, orgInfo);
		}
		return orgInfo;
	}
	
	public static String  getOrgName(String orgId){
		return get(orgId).getOrgName();
	}
	/**
	 * 清除所有机构缓存
	 */
	public static void clearAllOrgCache(){
		CacheUtils.removeCache(ORG_CACHE);
	}
	
	
	/**
	 * 清除指定机构缓存
	 * @param user
	 */
	public static void clearCache(OrgInfo orgInfo){
		CacheUtils.remove(ORG_CACHE, orgInfo.getOrgId());
	}
	
	
}
